package Teach;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * description:统计文件
 * author:zcx
 * lenovo
 * 时间：2022.01.18.14.11
 */
public class Pj7 {
    public static Map<String, List<String>> map=new HashMap<>();
    public static void main(String[] args) {
     count(System.getProperty(""));
        System.out.println(map);
        map.forEach((k,v)->System.out.printf("%s = %d %n %s %n",k,v.size(),v));
    }
    public static void count(File dir){
        if(dir.isDirectory()){
            for(File t: dir.listFiles()){
                if(t.isDirectory()){
                    count(t);
                }else {
                    String fn=t.getName();
                    String ext=fn.lastIndexOf(".")==-1?"未知":fn.substring(fn.lastIndexOf(".")+1);
                    if (map.containsKey(ext)) {
                        //map.put(ext,map.get(ext)+1);
                        List<String> list=map.get(ext);
                        list.add(t.getAbsolutePath());
                        map.put(ext,list);
                    }else {
                        //map.put(ext,1);
                        List<String> list=new ArrayList<String>();
                                list.add(t.getAbsolutePath());
                        map.put(ext,list);
                    }
                }
            }
        }
    }
    public static  void count(String dir){
        count(new File(dir));
    }
}
